﻿using BenCaoXuan.Infrastructure.Attr;
using BenCaoXuan.Infrastructure.Dto;
using BenCaoXuan.Infrastructure.Dto.Admin.customer;
using BenCaoXuan.Infrastructure.Dto.Admin.employee;
using BenCaoXuan.Service.Interface.admin;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BenCaoXuan.Api.Admin.Controllers.admin
{
    [ApiGroup("Admin(管理端模块)")]
    public class CustomerController : BaseController
    {
       
        private readonly I_Customer_Service _customer_Service;

        public CustomerController(I_Login_Service login_Service, I_Customer_Service customer_Service) : base(login_Service)
        {
           _customer_Service= customer_Service;
        }




        

        /// <summary>
        /// 管理端-新增潜在客户
        /// </summary>
        /// <param name="Dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Customer(AddCustomer_Dto dto) {
            var employee = this.Get_AdminUser();
            if (employee == null) {
                return Unauthorized();
            }

            var result = await _customer_Service.Add_Customer(dto,employee.id);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取当前员工下的客户信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Customer(int page=1,int limit=10,string? key="") {
            var employee = this.Get_AdminUser();
            if (employee == null)
            {
                return Unauthorized();
            }

            var result = await _customer_Service.Get_Customer(new Fenye_Dto() { 
            id=employee.id,
            page=page,
            limit=limit,
            key=key??""
            });
            return Ok(result);

        }

        /// <summary>
        /// 管理端-添加客户跟进记录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_CustomerFollow(AddCustomerFollow_Dto dto) {
            var employee = this.Get_AdminUser();
            if (employee == null)
            {
                return Unauthorized();
            }

            var result = await _customer_Service.Add_CustomerFollow(dto,employee.id);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取当前客户的跟进记录
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Customer_Follow(string? id) {
            var result = await _customer_Service.Get_Customer_Follow(id);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取所有的公海客户
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_HightSeasCustomer(int page = 1, int limit = 10, string? key = "",string? source="") {
            var result = await _customer_Service.Get_HightSeasCustomer(new Fenye_Dto() { 
            page=page,
            key=key??"",
            limit=limit,
            source=source??""
            });
            return Ok(result);
        }

        /// <summary>
        /// 管理端-领取公海客户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Claim_The_Customer(ClaimTheCustomer_Dto dto)
        {
            var employee = this.Get_AdminUser();
            if (employee == null)
            {
                return Unauthorized();
            }
            var result = await _customer_Service.Claim_The_Customer(dto, employee.id);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-完成客户跟进
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Completed_FollowUp(IsBan_Dto dto) {
            var employee = this.Get_AdminUser();
            if (employee == null)
            {
                return Unauthorized();
            }
            var result = await _customer_Service.Completed_FollowUp(dto,employee.id);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取客户的消费记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_ConsumptionRecords(string? id) { 
        var result=await _customer_Service.Get_ConsumptionRecords(id);
            return Ok(result);
        }
    }
}
